package com.gaogzhen.controller;

import com.gaogzhen.domain.Market;
import com.gaogzhen.domain.UserFavoriteMarket;
import com.gaogzhen.service.UserFavoriteMarketService;
import com.gaogzhen.utils.CurrentUser;
import com.gaogzhen.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author Administrator
 * @date 2022-12-10 17:21
 */
@RestController
@RequestMapping("/userFavorites")
@Api(tags = "用户市场收藏控制器")
public class UserFavoriteController {

    @Autowired
    private UserFavoriteMarketService userFavoriteMarketService;

    @PostMapping("/addFavorite")
    @ApiOperation(value = "用户收藏某个市场")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "market", value = "market json数据")
    })
    public R addFavorite(@RequestBody Market market) {
        userFavoriteMarketService.addFavorite(CurrentUser.getCurrentUserId(), market);
        return R.ok();
    }


    @DeleteMapping("/{symbol}")
    @ApiOperation(value = "取消市场收藏")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "symbol", value = "交易对")
    })
    public R cancelFavorite(@PathVariable("symbol") String symbol) {
        userFavoriteMarketService.cancelFavorite(CurrentUser.getCurrentUserId(), symbol);
        return R.ok();
    }
}
